<?php
/**
 * Creater: 李青林
 * Date Time : 2018/8/18 11:20
 */

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;


abstract class BaseFormRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function failedValidation( \Illuminate\Contracts\Validation\Validator $validator ) {

        exit(json_encode([
            'code'=>1,
            'msg'=>$this->getErrorInfoOne($validator->getMessageBag()->toArray()),
            'data'=>''])
        );

    }

    public function getErrorInfoOne($error)
    {
        $info=[];
        foreach($error as $key => $value){
            $info[]=  $value[0];
        }
        return $info[0];
    }
}